﻿using System;
using System.Windows.Media;

namespace Leow.TextEditor
{
    /// <summary>
    /// Represents a set of text formatting instructions to be applied on a
    /// line-by-line basis.
    /// </summary>
    public class LineBasedTextFormat : ITextFormat
    {
        private readonly Brush _brush;
        private readonly int _firstLineIndex;
        private readonly int _lastLineIndex;
        private readonly TextFormatMode _mode;

        /// <summary>
        /// Initializes a new instance of the <c>LineBasedTextFormat</c> class.
        /// </summary>
        /// <param name="mode">The text formatting mode.</param>
        /// <param name="brush">The brush used in drawing the text.</param>
        /// <param name="firstLineIndex">The index of the first line on which
        /// this text formatting will be applied to.</param>
        /// <param name="lastLineIndex">The index of the last line on which
        /// this text formatting will be applied to.</param>
        public LineBasedTextFormat(
            TextFormatMode mode,
            Brush brush,
            int firstLineIndex,
            int lastLineIndex)
        {
            _mode = mode;
            _brush = brush;
            _firstLineIndex = Math.Max(firstLineIndex, 0);
            _lastLineIndex = Math.Max(lastLineIndex, 0);
        }

        /// <summary>
        /// Gets the brush used in drawing the text.
        /// </summary>
        public Brush Brush
        {
            get
            {
                return _brush;
            }
        }

        /// <summary>
        /// Gets the index of the first line on which this text formatting is
        /// applied to.
        /// </summary>
        public int FirstLineIndex
        {
            get
            {
                return _firstLineIndex;
            }
        }

        /// <summary>
        /// Gets the index of the last line on which this text formatting is
        /// applied to.
        /// </summary>
        public int LastLineIndex
        {
            get
            {
                return _lastLineIndex;
            }
        }

        /// <summary>
        /// Gets the text formatting mode.
        /// </summary>
        public TextFormatMode Mode
        {
            get
            {
                return _mode;
            }
        }
    }
}
